package demo.socket;

import java.awt.FlowLayout;
import java.awt.Frame;
import java.awt.TextArea;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;

public class UdpRece {

	public static void main(String[] args) throws IOException {
		DatagramSocket ds = new DatagramSocket(10000);
		Frame f = new Frame("��������");
		TextArea ta = new TextArea(10, 50);
		f.setLayout(new FlowLayout());
		f.setBounds(600, 500, 400, 300);
		f.add(ta);
		f.addWindowListener(new WindowAdapter() {
			public void windowClosing(WindowEvent e) {
				ds.close();
				System.exit(0);
			}
		});
		f.setVisible(true);
		while (true) {
			byte[] b = new byte[1024];
			DatagramPacket dp = new DatagramPacket(b, b.length);
			ds.receive(dp);
			ta.append(dp.getAddress() + "����" + dp.getPort() + "����" + new String(dp.getData(), 0, dp.getLength())
					+ "\r\n");
		}
	}

}
